#ifndef LOGICMGR_H
#define LOGICMGR_H
#include "singleton.h"
#include <functional>
#include <QMap>
#include <QJsonObject>
#include <QObject>
#include <QThread>
#include <QFileInfo>

class LogicWorker: public QObject{
    Q_OBJECT
public:
    LogicWorker(QObject * parent = nullptr);
    void InitHandlers();
private:
    QMap<quint32, std::function<void(QJsonObject obj)> >_handlers;
signals:
      void sig_trans_size(int trans_size);
public slots:
    void slot_logic_process(quint16 msgid, QJsonObject obj);
};

//QObject 放在前面
class LogicMgr : public QObject, public Singleton<LogicMgr>
{
    Q_OBJECT
public:
    friend class Singleton<LogicMgr>;
    ~LogicMgr();
    std::shared_ptr<QFileInfo>  GetFileInfo(QString md5);
    void AddMD5File(QString md5, std::shared_ptr<QFileInfo> fileInfo);
    bool Pause();
    void SetPause(bool pause);
private:
    LogicMgr();


    LogicWorker* _worker;
    QThread* _work_thread;
    std::mutex _map_mtx;
    //md5->filename 的map
    QHash<QString, std::shared_ptr<QFileInfo>> _map_md5_file_info;
    std::atomic<bool> _b_pause;
signals:
    void sig_logic_process(quint16 msgid, QJsonObject obj);
    void sig_trans_size(int trans_size);
};

#endif // LOGICMGR_H
